import React from 'react';
import { inject, observer } from 'mobx-react';
import { Button } from 'antd';
import { WeaDialog, WeaLocaleProvider } from 'ecCom';
import * as dialogTypes from '../../../constants/OdocCompsDialogType';

const getLabel = WeaLocaleProvider.getLabel;

@inject('odocCompsStore')
@observer
class Index extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      hasLoad: false,
    };
  }

  componentDidMount() {
    const init = () => {
      this.setState({ hasLoad: true });
    };

    window.eventRegister && window.eventRegister.loadModule('workfolwPublic', init);
  }

  changeRemarkInfo = (params = {}) => {
    const { odocCompsStore } = this.props;
    const { workflowStores } = odocCompsStore;
    const { globalStore } = workflowStores;
    const { changeSubmitParam } = globalStore;
    changeSubmitParam(params);
  }


  getButtons = () => [
    <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@3zcycp@save`} type={'primary'} onClick={this.doSaveRmark}>{getLabel(86, '保存')}</Button>,
    <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@r69szc@cancel`} type={'ghost'} onClick={this.onCancel}>{getLabel(201, '取消')}</Button>,
  ]

  onCancel = () => {
    const { onClose } = this.props;
    onClose && typeof onClose == 'function' && (onClose(dialogTypes.ODOC_FILL_REMARK_DIALOG));
  }

  doSaveRmark = () => {
    let remark = window.CK_REF.odocFillRemarkCk.getEditor().getData();
    window.CK_REF.remark.getEditor().setData(remark);
    WfForm.rightBtn.doSave_nNew(false);
    this.onCancel();
  }

  render() {
    const { odocCompsStore = {} } = this.props;
    let { dialogVisible } = odocCompsStore;
    let visible = dialogVisible.get(dialogTypes.ODOC_FILL_REMARK_DIALOG);
    const layout = jQuery('.wf-req')[0];

    let dialogparams = {
      style: { width: 700, height: 291 },
      visible,
      title: getLabel(26039, '填写意见'),
      onCancel: this.onCancel,
      buttons: this.getButtons(),
      className: 'odocFillRemark',
      layout,
      icon: 'icon-coms-workflow',
      iconBgcolor: '#0179DE',
    };

    const { WfSignInput } = window.weaWorkflowPublic;
    const { workflowStores } = odocCompsStore;
    const { globalStore } = workflowStores;
    const { commonParam, markInfo = {}, loadMarkInfo } = globalStore;
    const { requestid, requestType } = commonParam;
    const { remarkInfo = {} } = markInfo;
    let { hasLoad } = this.state;
    return (
      <div className={'THTHTHHTH'}>
        <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@5ikxqu`}
          {...dialogparams}
        >
          <div style={{ padding: '10px' }}>
            {
              hasLoad && <WfSignInput ecId={`${this && this.props && this.props.ecId || ''}_WfSignInput@9k5ncj`}
                ref={'odocFillRemarkCk'}
                markInfo={markInfo}
                requestType={requestType}
                requestid={requestid}
                isShowSignInput={true}
                editorId={'odocFillRemarkCk'}
                {...remarkInfo}
                maxHeight={350}
                changeRemarkInfo={this.changeRemarkInfo}
                saveCallBack={loadMarkInfo}
              />
            }
          </div>
        </WeaDialog>
      </div>
    );
  }
}
export default Index;
